
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>LaunchWrapper · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="3.4.html" />
    
    
    <link rel="prev" href="3.2.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" >
            
                <a target="_blank" href="https://github.com/xfl03/CoreModTutor">
            
                    
                    源代码仓库（求star）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    目录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="0.html">
            
                <a href="0.html">
            
                    
                    0 绪论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    1 简介
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="1.1.html">
            
                <a href="1.1.html">
            
                    
                    CoreMod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="1.2.html">
            
                <a href="1.2.html">
            
                    
                    Java虚拟机
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="1.3.html">
            
                <a href="1.3.html">
            
                    
                    Minecraft混淆方式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    2 Java虚拟机
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" >
            
                <span>
            
                    
                    ClassLoader类加载器
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" >
            
                <span>
            
                    
                    ByteCode字节码
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" >
            
                <span>
            
                    
                    ASM
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    3 原版 CoreMod
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="3.1.html">
            
                <a href="3.1.html">
            
                    
                    直接修改class文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="3.2.html">
            
                <a href="3.2.html">
            
                    
                    JavaAgent
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.3" data-path="3.3.html">
            
                <a href="3.3.html">
            
                    
                    LaunchWrapper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="3.4.html">
            
                <a href="3.4.html">
            
                    
                    ModLauncher
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    4 FML CoreMod
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="4.1.html">
            
                <a href="4.1.html">
            
                    
                    1.3.2-1.5.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="4.2.html">
            
                <a href="4.2.html">
            
                    
                    1.6.1-1.12.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="4.3.html">
            
                <a href="4.3.html">
            
                    
                    1.13.2-1.14.4
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="5.html">
            
                <a href="5.html">
            
                    
                    5 Mixin
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="5.1.html">
            
                <a href="5.1.html">
            
                    
                    配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="5.2.html">
            
                <a href="5.2.html">
            
                    
                    引导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="5.3.html">
            
                <a href="5.3.html">
            
                    
                    注入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="5.4.html">
            
                <a href="5.4.html">
            
                    
                    修改
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="5.5.html">
            
                <a href="5.5.html">
            
                    
                    定位
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="5.6.html">
            
                <a href="5.6.html">
            
                    
                    融合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="5.7.html">
            
                <a href="5.7.html">
            
                    
                    扩展
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="5.8.html">
            
                <a href="5.8.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" >
            
                <span>
            
                    
                    附录
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="附录A.html">
            
                <a href="附录A.html">
            
                    
                    附录A 相关工具下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="附录B.html">
            
                <a href="附录B.html">
            
                    
                    附录B 常见Java字节码指令表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="附录C.html">
            
                <a href="附录C.html">
            
                    
                    附录C 参考资料
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >LaunchWrapper</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="launchwrapper">LaunchWrapper</h1>
<ul>
<li>1.6&#xFF0C;Minecraft&#x66F4;&#x6362;&#x4E86;&#x6E38;&#x620F;&#x76EE;&#x5F55;&#x7684;&#x7ED3;&#x6784;&#xFF0C;&#x4F7F;&#x5F97;&#x540C;&#x4E00;&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#x652F;&#x6301;&#x591A;&#x4E2A;&#x7248;&#x672C;&#x5171;&#x5B58;&#x3002;<br>&#x4E3A;&#x4E86;&#x914D;&#x5408;&#x8FD9;&#x4E00;&#x53D8;&#x5316;&#xFF0C;&#x542F;&#x52A8;&#x5668;&#x4E2D;&#x63D0;&#x4F9B;&#x4E86;&#x4ECE;alpha&#x3001;beta&#x7684;&#x5927;&#x90E8;&#x5206;&#x53D1;&#x5E03;&#x7248;&#x672C;&#x53CA;1.0.0-1.5.2&#x7684;&#x6B63;&#x5F0F;&#x7248;&#x672C;&#xFF0C;&#x800C;&#x8FD9;&#x4E9B;&#x7248;&#x672C;&#x6CE8;&#x5B9A;&#x662F;&#x4E0D;&#x652F;&#x6301;&#x65B0;&#x542F;&#x52A8;&#x5668;&#x4E0E;&#x65B0;&#x76EE;&#x5F55;&#x7ED3;&#x6784;&#x7684;&#xFF0C;&#x7528;&#x4E8E;&#x4FEE;&#x6539;&#x8001;&#x7248;&#x672C;&#x6E38;&#x620F;&#x517C;&#x5BB9;&#x6027;&#x7684;<a href="https://github.com/Mojang/LegacyLauncher" target="_blank">LaunchWrapper</a>&#x5E94;&#x8FD0;&#x800C;&#x751F;&#x3002;</li>
<li>&#x7531;&#x4E8E;LaunchWrapper&#x4E3B;&#x8981;&#x7531;Forge&#x56E2;&#x961F;&#x5236;&#x4F5C;&#xFF0C;&#x5176;&#x4EE3;&#x7801;&#x5927;&#x91CF;&#x53C2;&#x8003;&#x4E86;FML Relauncher&#xFF0C;LaunchWrapper&#x4E5F;&#x88AB;&#x7528;&#x4E8E;FML&#x5728;1.6-1.12.2&#x7684;&#x52A0;&#x8F7D;&#xFF0C;&#x4ECE;&#x6B64;&#x6446;&#x8131;&#x4E86;&#x4FEE;&#x6539;&#x6838;&#x5FC3;&#x6587;&#x4EF6;&#x7684;&#x5B89;&#x88C5;&#x65B9;&#x5F0F;&#x3002;    </li>
<li>LaunchWrapper&#x4E0D;&#x652F;&#x6301;Java9&#x53CA;&#x4EE5;&#x4E0A;&#x7684;&#x7248;&#x672C;&#x3002;</li>
</ul>
<h2 id="&#x52A0;&#x8F7D;&#x6D41;&#x7A0B;">&#x52A0;&#x8F7D;&#x6D41;&#x7A0B;</h2>
<p><a href="https://github.com/Mojang/LegacyLauncher/blob/master/src/main/java/net/minecraft/launchwrapper/Launch.java" target="_blank">Launch</a>&#x7C7B;&#x662F;LaunchWrapper&#x7684;&#x4E3B;&#x7C7B;&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x7C7B;&#x4E2D;&#x521B;&#x5EFA;&#x4E86;<code>LaunchClassLoader</code>&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x4E86;<code>ITweaker</code>&#xFF08;&#x4E0B;&#x79F0;Tweaker&#xFF09;&#x7684;&#x5217;&#x8868;&#xFF1A;</p>
<ul>
<li><p>&#x5728;<code>Launch</code>&#x7684;&#x6784;&#x9020;&#x5668;&#x4E2D;&#xFF0C;&#x521B;&#x5EFA;&#x4E86;<code>LaunchClassLoader</code>&#x7684;&#x5BF9;&#x8C61;&#xFF0C;<code>LaunchClassLoader</code>&#x662F;<code>URLClassLoader</code>&#x7684;&#x5B50;&#x7C7B;&#xFF0C;&#x5728;&#x521B;&#x5EFA;&#x8FC7;&#x7A0B;&#x4E2D;&#x4F20;&#x5165;&#x4E86;&#x5F53;&#x524D;&#x4F7F;&#x7528;&#x7684;<code>URLClassLoader</code>&#x4F7F;&#x7528;&#x7684;URLs&#xFF0C;&#x5E76;&#x66F4;&#x6539;&#x4E86;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x7684;<code>ClassLoader</code>&#xFF0C;&#x6B64;&#x540E;&#x7684;&#x7C7B;&#x52A0;&#x8F7D;&#x5747;&#x4F1A;&#x901A;&#x8FC7;<code>LaunchClassLoader</code>&#x8FDB;&#x884C;</p>
<pre><code class="lang-java"><span class="hljs-keyword">final</span> URLClassLoader ucl = (URLClassLoader) getClass().getClassLoader();
classLoader = <span class="hljs-keyword">new</span> LaunchClassLoader(ucl.getURLs());
...
Thread.currentThread().setContextClassLoader(classLoader);
</code></pre>
</li>
<li><p>&#x7531;&#x4E8E;&#x4ECE;Java9&#x5F00;&#x59CB;&#xFF0C;&#x4E0D;&#x518D;&#x9ED8;&#x8BA4;&#x4F7F;&#x7528;<code>URLClassLoader</code>&#x800C;&#x662F;<code>AppClassLoader</code>&#xFF0C;&#x5728;Java9&#x53CA;&#x4EE5;&#x4E0A;&#x7684;&#x7248;&#x672C;&#x8FD9;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#x4F1A;&#x53D1;&#x751F;<code>ClassCastException</code>&#x5BFC;&#x81F4;&#x6E38;&#x620F;<a href="https://github.com/Mojang/LegacyLauncher/pull/11" target="_blank">&#x5D29;&#x6E83;</a>&#xFF0C;&#x76F4;&#x5230;ModLauncher&#x624D;&#x4FEE;&#x590D;&#x4E86;&#x8FD9;&#x4E00;&#x95EE;&#x9898;</p>
<pre><code class="lang-java"><span class="hljs-keyword">final</span> URLClassLoader ucl = (URLClassLoader) getClass().getClassLoader();
</code></pre>
</li>
<li><p>&#x5728;<code>launch</code>&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x9996;&#x5148;&#x4ECE;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x4E2D;&#x8BFB;&#x53D6;&#x4E86;Tweaker&#x7684;&#x7C7B;&#x540D;</p>
<pre><code class="lang-java"><span class="hljs-keyword">final</span> OptionSpec&lt;String&gt; tweakClassOption = parser.accepts(<span class="hljs-string">&quot;tweakClass&quot;</span>, <span class="hljs-string">&quot;Tweak class(es) to load&quot;</span>).withRequiredArg().defaultsTo(DEFAULT_TWEAK);
...
<span class="hljs-keyword">final</span> List&lt;String&gt; tweakClassNames = <span class="hljs-keyword">new</span> ArrayList&lt;String&gt;(options.valuesOf(tweakClassOption));
</code></pre>
</li>
<li><p>&#x7ECF;&#x8FC7;&#x4E00;&#x756A;&#x6392;&#x9664;&#x91CD;&#x590D;&#x7684;&#x64CD;&#x4F5C;&#x540E;&#xFF0C;&#x4FBF;&#x4F7F;&#x7528;&#x53CD;&#x5C04;&#x6765;&#x5B9E;&#x4F8B;&#x5316;&#x4F20;&#x5165;&#x7684;Tweaker&#xFF0C;&#x5E76;&#x52A0;&#x5165;&#x5217;&#x8868;</p>
<pre><code class="lang-java"><span class="hljs-keyword">final</span> ITweaker tweaker = (ITweaker) Class.forName(tweakName, <span class="hljs-keyword">true</span>, classLoader).newInstance();
tweakers.add(tweaker);
</code></pre>
</li>
<li><p>&#x904D;&#x5386;<code>tweakers</code>&#x5217;&#x8868;&#x8C03;&#x7528;&#x63A5;&#x53E3;<code>ITweaker</code>&#x7684;<code>acceptOptions</code>&#x5C06;&#x542F;&#x52A8;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x5165;Tweaker&#xFF0C;&#x4EE5;&#x53CA;<code>injectIntoClassLoader</code>&#x4F1A;&#x4F20;&#x5165;&#x4F7F;&#x7528;&#x7684;<code>LaunchClassLoader</code></p>
<pre><code class="lang-java"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">final</span> Iterator&lt;ITweaker&gt; it = tweakers.iterator(); it.hasNext(); ) {
  <span class="hljs-keyword">final</span> ITweaker tweaker = it.next();
  LogWrapper.log(Level.INFO, <span class="hljs-string">&quot;Calling tweak class %s&quot;</span>, tweaker.getClass().getName());
  tweaker.acceptOptions(options.valuesOf(nonOption), minecraftHome, assetsDir, profileName);
  tweaker.injectIntoClassLoader(classLoader);
  allTweakers.add(tweaker);
  it.remove();
}
</code></pre>
</li>
<li><p>&#x4E0A;&#x9762;&#x6709;&#x4E00;&#x4E2A;&#x975E;&#x5E38;&#x7EC6;&#x8282;&#x7684;&#x8BBE;&#x8BA1;&#xFF0C;&#x904D;&#x5386;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x4ECE;<code>tweakers</code>&#x4E2D;&#x79FB;&#x9664;&#x5DF2;&#x904D;&#x5386;&#x7684;Tweaker&#xFF0C;&#x52A0;&#x5165;<code>allTweakers</code>&#x4E2D;&#xFF0C;&#x518D;&#x914D;&#x5408;&#x4E0A;&#x4E00;&#x4E2A;&#x68C0;&#x6D4B;<code>tweakClassNames</code>&#x662F;&#x5426;&#x5DF2;&#x7A7A;&#x7684;&#x5FAA;&#x73AF;&#xFF0C;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x65B9;&#x4FBF;&#x7684;&#x8BA9;Tweaker&#x5728;&#x4E0A;&#x8FF0;&#x8FC7;&#x7A0B;&#x4E2D;&#x52A8;&#x6001;&#x52A0;&#x5165;&#x65B0;&#x7684;Tweaker&#xFF0C;&#x800C;&#x4E0D;&#x9700;&#x8981;&#x5728;&#x542F;&#x52A8;&#x53C2;&#x6570;&#x4E2D;&#x6307;&#x5B9A;&#x6240;&#x6709;&#x7684;Tweaker</p>
<pre><code class="lang-java">allTweakers.add(tweaker);
it.remove();
</code></pre>
<pre><code class="lang-java">...
<span class="hljs-keyword">while</span> (!tweakClassNames.isEmpty());
</code></pre>
</li>
<li><p>&#x5728;&#x521D;&#x59CB;&#x5316;&#x5B8C;&#x6240;&#x6709;&#x7684;Tweaker&#x540E;&#xFF0C;&#x4ECE;Tweaker&#x4E2D;&#x91CD;&#x65B0;&#x83B7;&#x5F97;&#x542F;&#x52A8;&#x53C2;&#x6570;&#xFF0C;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x8FD9;&#x4E2A;&#x542F;&#x52A8;&#x53C2;&#x6570;&#x662F;&#x6240;&#x6709;Tweaker&#x53C2;&#x6570;&#x7684;&#x7B80;&#x5355;&#x5408;&#x5E76;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x91CD;&#x590D;&#x53C2;&#x6570;&#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x81F4;JOpt Simple&#x65E0;&#x6CD5;&#x6309;&#x7167;Minecraft&#x7684;&#x8981;&#x6C42;&#x8BFB;&#x53D6;&#x53C2;&#x6570;&#x800C;&#x5D29;&#x6E83;</p>
<pre><code class="lang-java"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">final</span> ITweaker tweaker : allTweakers) {
  argumentList.addAll(Arrays.asList(tweaker.getLaunchArguments()));
}
</code></pre>
</li>
<li><p>&#x6700;&#x540E;&#x8C03;&#x7528;&#x7B2C;&#x4E00;&#x4E2A;Tweaker&#x7684;<code>getLaunchTarget</code>&#x65B9;&#x6CD5;&#x83B7;&#x5F97;&#x76EE;&#x6807;&#x542F;&#x52A8;&#x7C7B;&#xFF0C;&#x5E76;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x7C7B;&#x7684;main&#x65B9;&#x6CD5;</p>
<pre><code class="lang-java"><span class="hljs-keyword">final</span> String launchTarget = primaryTweaker.getLaunchTarget();
<span class="hljs-keyword">final</span> Class&lt;?&gt; clazz = Class.forName(launchTarget, <span class="hljs-keyword">false</span>, classLoader);
<span class="hljs-keyword">final</span> Method mainMethod = clazz.getMethod(<span class="hljs-string">&quot;main&quot;</span>, <span class="hljs-keyword">new</span> Class[]{String[].class});
...
mainMethod.invoke(<span class="hljs-keyword">null</span>, (Object) argumentList.toArray(<span class="hljs-keyword">new</span> String[argumentList.size()]));
</code></pre>
</li>
</ul>
<p><a href="https://github.com/Mojang/LegacyLauncher/blob/master/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java" target="_blank">LaunchClassLoader</a>&#x662F;LaunchWrapper&#x52A0;&#x8F7D;Minecraft&#x6240;&#x4F7F;&#x7528;<code>ClassLoader</code>&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x7C7B;&#x4E2D;&#x5B8C;&#x6210;&#x4E86;&#x7C7B;&#x52A0;&#x8F7D;&#x4E0E;<code>transform</code>&#xFF1A;</p>
<ul>
<li><p>&#x5148;&#x628A;&#x76EE;&#x5149;&#x805A;&#x7126;&#x4E8E;<code>loadClass</code>&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4F20;&#x5165;&#x4E00;&#x4E2A;class&#x540D;&#xFF0C;&#x9700;&#x8981;&#x8FD4;&#x56DE;<code>Class</code>&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x7B80;&#x800C;&#x8A00;&#x4E4B;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x7528;&#x4E8E;&#x52A0;&#x8F7D;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E2D;&#x9700;&#x8981;&#x5B8C;&#x6210;&#x4E24;&#x5927;&#x4EFB;&#x52A1;&#x2014;&#x2014;&#x52A0;&#x8F7D;&#x7C7B;&#x3001;&#x4FEE;&#x6539;&#x7C7B;</p>
</li>
<li><p>&#x9996;&#x5148;&#xFF0C;<code>classLoaderExceptions</code>&#x5217;&#x8868;&#x8BB0;&#x5F55;&#x4E86;&#x5E94;&#x5F53;&#x4ECE;&#x539F;&#x5148;&#x7684;<code>ClassLoader</code>&#x4E2D;&#x52A0;&#x8F7D;&#x7684;&#x7C7B;&#xFF0C;<code>transformerExceptions</code>&#x8BB0;&#x5F55;&#x4E86;&#x4E0D;&#x5E94;&#x8BE5;&#x88AB;&#x4FEE;&#x6539;&#x7684;&#x7C7B;</p>
<pre><code class="lang-java"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">final</span> String exception : classLoaderExceptions) {
  <span class="hljs-keyword">if</span> (name.startsWith(exception)) {
      <span class="hljs-keyword">return</span> parent.loadClass(name);
  }
}
...
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">final</span> String exception : transformerExceptions) {
  <span class="hljs-keyword">if</span> (name.startsWith(exception)) {
      <span class="hljs-keyword">try</span> {
          <span class="hljs-keyword">final</span> Class&lt;?&gt; clazz = <span class="hljs-keyword">super</span>.findClass(name);
          ...
          <span class="hljs-keyword">return</span> clazz;
      } <span class="hljs-keyword">catch</span> (ClassNotFoundException e) {
          ...
          <span class="hljs-keyword">throw</span> e;
      }
  }
}
</code></pre>
</li>
<li><p>&#x5BF9;&#x4E8E;&#x4E00;&#x4E2A;&#x53EF;&#x4EE5;&#x88AB;&#x4FEE;&#x6539;&#x7684;class&#xFF0C;&#x4F1A;&#x8C03;&#x7528;<code>runTransformers</code>&#x65B9;&#x6CD5;&#x6765;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;<code>Class</code>&#x7684;&#x5BF9;&#x8C61;</p>
<pre><code class="lang-java"><span class="hljs-keyword">final</span> <span class="hljs-keyword">byte</span>[] transformedClass = runTransformers(untransformedName, transformedName, getClassBytes(untransformedName));
...
<span class="hljs-keyword">final</span> Class&lt;?&gt; clazz = defineClass(transformedName, transformedClass, <span class="hljs-number">0</span>, transformedClass.length, codeSource);
...
<span class="hljs-keyword">return</span> clazz;
</code></pre>
</li>
<li><p>&#x5728;<code>runTransformers</code>&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x4F9D;&#x6B21;&#x8C03;&#x7528;Transformer&#x5BF9;&#x7C7B;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x4FEE;&#x6539;&#x540E;&#x7684;&#x7C7B;</p>
<pre><code class="lang-java"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">final</span> IClassTransformer transformer : transformers) {
  basicClass = transformer.transform(name, transformedName, basicClass);
}
...
<span class="hljs-keyword">return</span> basicClass;
</code></pre>
</li>
</ul>
<h2 id="&#x5236;&#x4F5C;&#x65B9;&#x6CD5;">&#x5236;&#x4F5C;&#x65B9;&#x6CD5;</h2>
<p>&#x4EE5;&#x4E0A;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5F97;&#x77E5;&#x4E24;&#x4E2A;&#x5173;&#x952E;&#x4FE1;&#x606F;&#x2014;&#x2014;<code>ITweaker</code>&#x4EE5;&#x53CA;<code>IClassTransformer</code>&#x3002;</p>
<h3 id="itweaker">ITweaker</h3>
<p><a href="https://github.com/Mojang/LegacyLauncher/blob/master/src/main/java/net/minecraft/launchwrapper/ITweaker.java" target="_blank">ITweaker</a>&#x63A5;&#x53E3;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4EE5;&#x4E0B;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li><code>acceptOptions</code>&#xFF0C;&#x63A5;&#x6536;Minecraft&#x542F;&#x52A8;&#x53C2;&#x6570;&#xFF0C;<code>args</code>&#x662F;LaunchWrapper&#x5C1A;&#x672A;&#x8BFB;&#x53D6;&#x7684;&#x53C2;&#x6570;&#xFF0C;<code>gameDir</code>&#x662F;&#x6E38;&#x620F;&#x8DEF;&#x5F84;&#xFF0C;<code>assetsDir</code>&#x662F;<code>assets</code>&#x6587;&#x4EF6;&#x5939;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;<code>profile</code>&#x662F;&#x7248;&#x672C;&#x540D;&#x79F0;</li>
<li><code>injectIntoClassLoader</code>&#xFF0C;&#x53C2;&#x6570;<code>classLoader</code>&#x4E3A;&#x5C06;&#x8981;&#x7528;&#x4E8E;&#x52A0;&#x8F7D;Minecraft&#x7684;<code>LaunchClassLoader</code>&#x5BF9;&#x8C61;&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x53EF;&#x4F7F;&#x7528;<code>registerTransformer</code>&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x6CE8;&#x518C;<code>IClassTransformer</code>&#x7B49;&#x64CD;&#x4F5C;<code>LaunchClassLoader</code>&#x7684;&#x884C;&#x4E3A;</li>
<li><code>getLaunchTarget</code>&#xFF0C;&#x8FD4;&#x56DE;&#x9700;&#x8981;&#x542F;&#x52A8;&#x7684;&#x4E3B;&#x7C7B;&#xFF0C;&#x4E00;&#x822C;&#x4E3A;<code>net.minecraft.client.main.Main</code>&#xFF0C;&#x4EE5;&#x7B2C;&#x4E00;&#x4E2A;Tweaker&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;&#x51C6;</li>
<li><code>getLaunchArguments</code>&#xFF0C;&#x8FD4;&#x56DE;Minecraft&#x53C2;&#x6570;&#xFF0C;&#x8BF7;&#x6CE8;&#x610F;&#x9700;&#x8981;&#x8FD4;&#x56DE;Minecraft&#x6240;&#x9700;&#x7684;&#x6240;&#x6709;&#x53C2;&#x6570;</li>
</ul>
<p>&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;<code>ITweaker</code>&#x5B9E;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> java.io.File;
<span class="hljs-keyword">import</span> java.util.Arrays;
<span class="hljs-keyword">import</span> java.util.ArrayList;
<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-keyword">import</span> net.minecraft.launchwrapper.ITweaker;
<span class="hljs-keyword">import</span> net.minecraft.launchwrapper.LaunchClassLoader;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ExampleTweaker</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">ITweaker</span> </span>{

    <span class="hljs-keyword">private</span> String[] args;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">acceptOptions</span><span class="hljs-params">(List&lt;String&gt; args, File gameDir, File assetsDir, String profile)</span> </span>{
        String[] additionArgs = {<span class="hljs-string">&quot;--gameDir&quot;</span>, gameDir.getAbsolutePath(), <span class="hljs-string">&quot;--assetsDir&quot;</span>, assetsDir.getAbsolutePath(), <span class="hljs-string">&quot;--version&quot;</span>, profile};
        List&lt;String&gt; fullArgs =  <span class="hljs-keyword">new</span> ArrayList&lt;String&gt;();
        fullArgs.addAll(args);
        fullArgs.addAll(Arrays.asList(additionArgs));
        <span class="hljs-keyword">this</span>.args = fullArgs.toArray(<span class="hljs-keyword">new</span> String[fullArgs.size()]);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">injectIntoClassLoader</span><span class="hljs-params">(LaunchClassLoader classLoader)</span> </span>{
        classLoader.registerTransformer(<span class="hljs-string">&quot;com.example.ClassTransformer&quot;</span>);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getLaunchTarget</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;net.minecraft.client.main.Main&quot;</span>;
    }

    <span class="hljs-keyword">public</span> String[] getLaunchArguments() {
        <span class="hljs-keyword">return</span> args;
    }
}
</code></pre>
<h1 id="iclasstransformer">IClassTransformer</h1>
<p><code>IClassTransformer</code>&#x662F;LaunchWrapper&#x63D0;&#x4F9B;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4EE5;&#x4E0B;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li><code>transform</code>&#xFF0C;&#x63A5;&#x6536;<code>name</code>&#x3001;<code>transformedName</code>&#x4E0E;<code>basicClass</code>&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5206;&#x522B;&#x662F;&#x539F;&#x7C7B;&#x540D;&#x3001;&#x53CD;&#x6DF7;&#x6DC6;&#x7C7B;&#x540D;&#x548C;class&#x6587;&#x4EF6;&#x7684;&#x4E8C;&#x8FDB;&#x5236;<code>byte</code>&#x6570;&#x7EC4;&#xFF0C;&#x9700;&#x8981;&#x8FD4;&#x56DE;&#x4FEE;&#x6539;&#x540E;&#x7684;class&#x6587;&#x4EF6;&#x7684;<code>byte</code>&#x6570;&#x7EC4;</li>
</ul>
<p>&#x9700;&#x8981;&#x7279;&#x522B;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF1A;</p>
<ul>
<li><code>name</code>&#x539F;&#x7C7B;&#x540D;&#x548C;<code>basicClass</code> class&#x6587;&#x4EF6;&#xFF0C;&#x5728;&#x6E38;&#x620F;&#x8FD0;&#x884C;&#x65F6;&#x4E3A;notch&#x6DF7;&#x6DC6;</li>
<li><code>transformedName</code>&#x53EA;&#x6709;&#x5F53;<code>IClassNameTransformer</code>&#x5B58;&#x5728;&#x65F6;&#x624D;&#x4F1A;&#x4E0E;<code>name</code>&#x4E0D;&#x540C;&#xFF0C;&#x5177;&#x4F53;&#x53CD;&#x6DF7;&#x6DC6;&#x65B9;&#x5F0F;&#x53D6;&#x51B3;&#x4E8E;<code>IClassNameTransformer</code>&#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x4F8B;&#x5982;FML&#x4F1A;&#x5C06;&#x5176;&#x53CD;&#x6DF7;&#x6DC6;&#x6210;mcp&#x540D;&#x79F0;</li>
<li><code>basicClass</code>&#x53EF;&#x80FD;&#x5DF2;&#x88AB;&#x5176;&#x4ED6;<code>IClassTransformer</code>&#x4FEE;&#x6539;&#x8FC7;</li>
<li>&#x5207;&#x8BB0;&#x65E0;&#x8BBA;&#x5982;&#x4F55;&#x90FD;&#x8981;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6709;&#x6548;&#x7684;<code>byte</code>&#x6570;&#x7EC4;&#xFF0C;&#x5426;&#x5219;&#x4F1A;&#x5BFC;&#x81F4;<code>ClassNotFoundException</code>&#x3001;<code>NoClassDefFoundError</code>&#x7B49;&#x5BFC;&#x81F4;&#x7684;&#x5D29;&#x6E83;</li>
</ul>
<p>&#x4E00;&#x4E2A;&#x6CA1;&#x6709;&#x5BF9;class&#x8FDB;&#x884C;&#x4EFB;&#x4F55;&#x4FEE;&#x6539;&#x7684;<code>IClassTransformer</code>&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> net.minecraft.launchwrapper.IClassTransformer;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ClassTransformer</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">IClassTransformer</span> </span>{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">byte</span>[] transform(String name, String transformedName, <span class="hljs-keyword">byte</span>[] basicClass) {
        <span class="hljs-keyword">return</span> basicClass;<span class="hljs-comment">//&#x7279;&#x522B;&#x6CE8;&#x610F;&#x9700;&#x8981;&#x8FD4;&#x56DE;basicClass</span>
    }
}
</code></pre>
<h2 id="&#x5B89;&#x88C5;&#x65B9;&#x6CD5;">&#x5B89;&#x88C5;&#x65B9;&#x6CD5;</h2>
<h3 id="&#x5E93;&#x6587;&#x4EF6;&#x6302;&#x8F7D;">&#x5E93;&#x6587;&#x4EF6;&#x6302;&#x8F7D;</h3>
<ul>
<li>&#x590D;&#x5236;&#x7248;&#x672C;json&#x5230;&#x53E6;&#x4E00;&#x4E2A;&#x7248;&#x672C;&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#xFF0C;&#x5E76;&#x4FEE;&#x6539;&#x5BF9;&#x5E94;&#x7684;&#x540D;&#x79F0;</li>
<li>&#x5728;<code>libraries</code>&#x4E2D;&#x52A0;&#x5165;LaunchWrapper&#x4E0E;&#x81EA;&#x5DF1;&#x7F16;&#x5199;&#x7684;Tweaker&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;<pre><code class="lang-json">{
  <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;com.example:ExampleTweaker:1.0&quot;</span>
},
{
  <span class="hljs-string">&quot;name&quot;</span>:<span class="hljs-string">&quot;net.minecraft:launchwrapper:1.12&quot;</span>
}
</code></pre>
</li>
<li>&#x4FEE;&#x6539;<code>mainClass</code>&#x4E3A;<code>net.minecraft.launchwrapper.Launch</code></li>
<li>&#x5728;<code>arguments</code>&#x4E2D;&#x52A0;&#x5165;<code>--tweakClass com.example.ExampleTweaker</code></li>
</ul>
<h3 id="&#x4F7F;&#x7528;modloader&#x52A0;&#x8F7D;">&#x4F7F;&#x7528;ModLoader&#x52A0;&#x8F7D;</h3>
<ul>
<li>FML&#x4E0E;LiteLoader&#x7684;1.6-1.12.2&#x5747;&#x652F;&#x6301;&#x52A0;&#x8F7D;Tweaker&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x5728;Manifest&#x4E2D;&#x5199;&#x5165;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;&#xFF1A;<pre><code>TweakClass&#xFF1A; com.example.AnotherExampleTweaker
</code></pre></li>
<li>&#x653E;&#x5165;<code>.minecraft/mods</code>&#x6587;&#x4EF6;&#x5939;&#x5373;&#x53EF;</li>
</ul>
<h2 id="&#x5F0A;&#x7AEF;">&#x5F0A;&#x7AEF;</h2>
<ul>
<li>&#x4E00;&#x822C;&#x9700;&#x8981;&#x81EA;&#x5E26;&#x6620;&#x5C04;&#x8868;&#x6216;&#x52A8;&#x6001;&#x6620;&#x5C04;&#x6765;&#x8FDB;&#x884C;&#x7248;&#x672C;&#x517C;&#x5BB9;&#xFF0C;&#x4E0D;&#x80FD;&#x4FDD;&#x8BC1;&#x8FD0;&#x884C;&#x65F6;&#x4E00;&#x5B9A;&#x5B58;&#x5728;<code>IClassNameTransformer</code></li>
<li>&#x4F7F;&#x7528;ModLoader&#x548C;&#x5E93;&#x6587;&#x4EF6;&#x6302;&#x8F7D;&#x96BE;&#x4EE5;&#x4F7F;&#x7528;&#x540C;&#x4E00;&#x4E2A;Tweaker&#xFF0C;&#x5904;&#x7406;&#x53C2;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#x4E0D;&#x540C;</li>
<li>&#x53C2;&#x6570;&#x4E2D;&#x591A;&#x4E2A;<code>tweakClass</code>&#x6781;&#x6709;&#x53EF;&#x80FD;&#x51FA;&#x9519;&#xFF0C;Tweaker&#x91CD;&#x590D;&#x5904;&#x7406;&#x6216;&#x90FD;&#x4E0D;&#x5904;&#x7406;&#x542F;&#x52A8;&#x53C2;&#x6570;&#x5747;&#x4F1A;&#x5BFC;&#x81F4;Minecraft&#x65E0;&#x6CD5;&#x6B63;&#x5E38;&#x542F;&#x52A8;</li>
<li>&#x5E93;&#x6587;&#x4EF6;&#x6302;&#x8F7D;&#x8F83;&#x4E3A;&#x9EBB;&#x70E6;&#xFF0C;&#x6700;&#x7EC8;&#x4ECD;&#x7136;&#x9700;&#x8981;&#x4F9D;&#x8D56;ModLoader</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="3.2.html" class="navigation navigation-prev " aria-label="Previous page: JavaAgent">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="3.4.html" class="navigation navigation-next " aria-label="Next page: ModLauncher">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"LaunchWrapper","level":"1.6.3","depth":2,"next":{"title":"ModLauncher","level":"1.6.4","depth":2,"path":"3.4.md","ref":"3.4.md","articles":[]},"previous":{"title":"JavaAgent","level":"1.6.2","depth":2,"path":"3.2.md","ref":"3.2.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"3.3.md","mtime":"2019-09-08T03:15:01.473Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-09-08T04:47:05.818Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

